package com.cn.io.bio;

import java.io.*;

public class StreamIo {


    public static void main(String[] args) throws IOException {
        InputStream inputStream = null;
        OutputStream outputStream = null;
        try {
            inputStream = new BufferedInputStream(new FileInputStream("D:\\opt\\abc.txt"));
            outputStream = new BufferedOutputStream(new FileOutputStream("D:\\opt\\def.txt"));
            byte[] byteBuffer = new byte[1024];
            while (inputStream.read(byteBuffer) != -1) {
                outputStream.write(byteBuffer);
            }
            //在缓冲区写完之后要记得调用flush()清空缓冲区。强行将缓冲区中的数据写出。否则可能无法写出数据
            outputStream.flush();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (inputStream != null) {
                inputStream.close();
            }
            if (outputStream != null) {
                outputStream.close();
            }
        }
    }
}
